package com.timeste.lasttime;

import java.util.Comparator;

public class LastTimeEvent implements Comparator<LastTimeEvent> {

	//private variables
	int _id;
	String _title;
	String _description;
	int _year;
	int _month;
	int _day;
	
	// Empty constructor
	public LastTimeEvent(){
		
	}
	
	
	public LastTimeEvent(int _id, String _title, String _description,
			int _year, int _month, int _day) {
		this._id = _id;
		this._title = _title;
		this._description = _description;
		this._year = _year;
		this._month = _month;
		this._day = _day;
	}
	
	public LastTimeEvent(String _title, String _description,
			int _year, int _month, int _day) {
		this._title = _title;
		this._description = _description;
		this._year = _year;
		this._month = _month;
		this._day = _day;
	}
	
	public int get_id() {
		return _id;
	}


	public void set_id(int _id) {
		this._id = _id;
	}


	public String get_title() {
		return _title;
	}


	public void set_title(String _title) {
		this._title = _title;
	}


	public String get_description() {
		return _description;
	}


	public void set_description(String _description) {
		this._description = _description;
	}


	public int get_year() {
		return _year;
	}


	public void set_year(int _year) {
		this._year = _year;
	}


	public int get_month() {
		return _month;
	}


	public void set_month(int _month) {
		this._month = _month;
	}


	public int get_day() {
		return _day;
	}


	public void set_day(int _day) {
		this._day = _day;
	}


    @Override
    public int compare(LastTimeEvent o1, LastTimeEvent o2) {
    	Integer y1 = Integer.valueOf(o1.get_year());
    	Integer y2 = Integer.valueOf(o2.get_year());
    	int yearCompare = y1.compareTo(y2);
    	if(yearCompare==0) {
    		Integer m1 = Integer.valueOf(o1.get_month());
        	Integer m2 = Integer.valueOf(o2.get_month());
    		int monthCompare = m1.compareTo(m2);
        	if(monthCompare==0) {
        		Integer d1 = Integer.valueOf(o1.get_day());
            	Integer d2 = Integer.valueOf(o2.get_day());
        		return (d1.compareTo(d2));
        	}
        	return monthCompare;
    	}
        return yearCompare;
    }
    
    @Override
    public String toString() {
    	StringBuilder sb = new StringBuilder("id: ");
    	sb.append(this._id);
    	sb.append(" title: ");
    	sb.append(this._title);
    	sb.append(" description: ");
    	sb.append(this._description);
    	sb.append(" year: ");
    	sb.append(this._year);
    	sb.append(" month: ");
    	sb.append(this._month);
    	sb.append(" day: ");
    	sb.append(this._day);
    	return sb.toString();
    }
}
